package com.xzit.headline.activity;

import android.os.Bundle;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

import com.j256.ormlite.dao.Dao;
import com.xzit.headline.R;
import com.xzit.headline.adapter.FavouriteListAdapter;
import com.xzit.headline.bean.NewListData;
import com.xzit.headline.db.MyDbHelper;

import java.sql.SQLException;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class FavouriteActivity extends AppCompatActivity {

    @BindView(R.id.listView)
    ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_favourite);
        ButterKnife.bind(this);

        //1.收藏列表初始化

        //2.查询数据
        queryDb();

        //3.显示
        setDataToList();
    }

    private List<NewListData.DataBean.NewsBean> list;

    private void queryDb() {
        MyDbHelper myDbHelper = new MyDbHelper(this);
        try {
            Dao<NewListData.DataBean.NewsBean, Integer> dao = myDbHelper.getDao(NewListData.DataBean.NewsBean.class);

            list = dao.queryForAll();

            System.out.println("我的数据:" + list);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    private void setDataToList() {
        FavouriteListAdapter adapter = new FavouriteListAdapter(list, this);
        listView.setAdapter(adapter);
    }
}
